class Solution {
public:
    int search(vector<int> &nums, int target)
    {
        int low = 0;
        int high = nums.size();
        while(low != high) {
            const int mid = (low + high) / 2;
            if(nums[mid] == target)
                return mid;
            if(nums[low] <= nums[mid]) {
                if(nums[low] <= target && target < nums[mid])
                    high = mid;
                else
                    low = mid + 1;
            } else {
                if(nums[mid] < target && target <= nums[high - 1])
                    low = mid + 1;
                else
                    high = mid;
            }
        }
        return -1;
    }
};
